﻿using System;
using System.Web;

namespace SBPweb.Messenger.Host.Services
{

    public abstract class MessengerManagerBase<T>
    {

        public T Messenger
        {
            get
            {
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.Session[GetKey()] == null)
                    {
                        HttpContext.Current.Session[GetKey()] = CreateInstance();
                    }
                    return (T)(HttpContext.Current.Session[GetKey()]);
                }
                return default(T);
            }
        }

        protected abstract T CreateInstance();

        protected static string GetKey()
        {
            return string.Format("_Messenger_{0}", typeof(T));
        }

    }

}